package org.agilelang.fgl.scanner;

/*
 AgileLang - A fourth generation language(http://www.agilelang.org).

 Copyright (C) 2013 Roderick Cusirramos (roderick20@hotmail.com)

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

public class TransitionMatrix {
    
    int[][] transition = {
        
        /*0*/{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        /*1*/{0, 0, 2/* 1,2 */, 0, 0, 1/* 1,5 */, 1/* 1,6 */, 1/* 1,7 */, 1/* 1,8 */, 100/* 1,9 */, 0, 1/*1,11*/},
        /*2*/{0, 0, 2/* 2,2 */, 3/* 2,3 */, 4/* 2,4 */, 9/* 2,5 */, 2/* 2,6 */, 2/* 2,7 */, 1/* 2,8 */, 0, 0, 1/* 4,11 */, 0},
        /*3*/{0, 0, 2/* 3,2 */, 0, 0, 0, 0, 0, 0, 1/* 3,11 */, 0},
        /*4*/{0, 0, 2/* 4,2 */, 0, 0, 9/* 4,5 */, 0, 0, 0, 0, 0, 1/* 4,11 */, 0},
        /*5*/{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/* 5,11 */, 0},
        /*6*/{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/* 6,11 */, 0},
        /*7*/{0, 0, 0, 0, 0, 0, 0, 0, 1/* 7,8 */, 0, 1/* 7,11 */, 0},
        /*8*/{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/* 8,11 */, 0},
        /*9*/{0, 0, 0, 0, 0, 0, 0, 0, 0, 100/* 9,9 */, 1/* 9,11 */, 0},
       /*10*/{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/* 10,11 */},
       /*11*/{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1/* 11,11 */},
       /*12*/{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    
    
    }; 
    
    TransitionMatrix(){
        
    }

    int move(int current_state, int ch) { 
        return transition[current_state][getTypeCharacter(ch)];
    }
    
    int getTypeCharacter( int ch) {        
        if (Character.isLetter((char) ch) || Character.isDigit((char) ch)) {
            return 2;
        } else if ((char) ch == '.') {
            return 3;
        } else if ((char) ch == '(') {
            return 4;
        } else if ((char) ch == ')') {
            return 5;
        } else if ((char) ch == '=') {
            return 6;
        } else if ((char) ch == '"') {
            return 7;
        } else if ((char) ch == ',') {
            return 8;
        } else if ((char) ch == ';') {
            return 9;
        } else if ((char) ch == '/') {
            return 10;
        } else if ( ch == 13 || ch == 10 || (char) ch == ' '|| (char) ch == '_'|| (char) ch == '*'|| (char) ch == '{'|| (char) ch == '}'|| (char) ch == ':'|| (char) ch == '\''|| (char) ch == '+'|| (char) ch == '-') { //\n
            return 11;
        } else if ((char) ch == '\t') {
            return 11;
        } else if ((char) ch == '\\') {
            return 13;
        }
        return 0;
    }    
}
